package com.fhz.shop.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModel;

/**
 * 时间:2023/8/22
 *
 * @author Mr.Feng
 * 简述: 基础fragment
 */
public abstract class BaseFragment<VM extends ViewModel,DB extends ViewDataBinding> extends Fragment {

    protected VM viewModel;
    protected DB binding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
        viewModel = createViewModel();
        initData();
        return binding.getRoot();

    }

    protected abstract void initData();
    protected abstract int getLayoutId();
    protected abstract VM createViewModel();


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}
